// https://www.luogu.com.cn/problem/P1090

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n, t;
    scanf("%d", &n);
    priority_queue<int, vector<int>, greater<int>> Q;
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        Q.push(t);
    }

    int ans = 0;
    while (Q.size() > 1) {
        const int c1 = Q.top();
        Q.pop();
        const int c2 = Q.top();
        Q.pop();

        int d = c1 + c2;
        Q.push(d);
        ans += d;
    }

    printf("%d\n", ans);
    return 0;
}